package com.lgd.factoryattendance.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lgd.factoryattendance.Bean.ElectricalGalleryType;
import com.lgd.factoryattendance.R;

import java.util.List;

/**
 * @Author lgd
 * @Date 2024/5/16 15:01
 *  自定义 电气类型 下拉框
 */
public class ElectricGalleryTypeSpinnerAdapter extends BaseAdapter {

    private List<ElectricalGalleryType> electricalGalleryTypeList;
    private Context context;
    private LayoutInflater layoutInflater;

    public ElectricGalleryTypeSpinnerAdapter(List<ElectricalGalleryType> electricalGalleryTypeList, Context context) {
        this.electricalGalleryTypeList = electricalGalleryTypeList;
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return electricalGalleryTypeList == null ? 0 : electricalGalleryTypeList.size();
    }

    @Override
    public Object getItem(int position) {
        return electricalGalleryTypeList == null ? null : electricalGalleryTypeList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = layoutInflater.inflate(R.layout.gallery_type_spinner, parent, false);
            holder = new ViewHolder();
            holder.tv_galleryType = convertView.findViewById(R.id.tv_galleryType);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        //  数据 填报
        ElectricalGalleryType electricalGalleryType = electricalGalleryTypeList.get(position);
        holder.tv_galleryType.setText(electricalGalleryType.getElectricaltypename());
        return convertView;
    }

    //  视图
    static class ViewHolder {
        TextView tv_galleryType;
    }

}
